import{ createRouter,
    createWebHistory }
    from 'vue-router'
<<<<<<< HEAD
import UploadView from "@/components/UploadFile.vue";
import LoginView from "@/views/LoginView.vue";
const routes = [
    {
        path: '/login',
        name: 'Login',
        component: LoginView,
        meta: { requiresAuth: false }
    },
    {
        path:'/upload',
        name: 'Upload',
        component: UploadView,
        meta: { requiresAuth: true }
    },
    {
        path: '/',
        redirect: '/login' // 默认重定向到登录页
    }

=======
import UploadView from "@/views/UploadView.vue";
const routes = [
    {
        path:'/upload',
        name: 'Upload',
        component: UploadView
    }
>>>>>>> f425cfb0320ced29f9e28f379fa4c77eebf50d68
]
const router = createRouter ({
    history:createWebHistory(),
    routes
<<<<<<< HEAD
});

router.beforeEach((to, from, next) => {
    const isAuthenticated = localStorage.getItem('token');
    console.log('路由守卫触发 - 目标路由:', to.name);
    console.log('是否已认证:', isAuthenticated ? '是' : '否');

    if (to.meta.requiresAuth && !isAuthenticated) {
        console.log('需要登录但未登录，重定向到登录页');
        next('/login');
    } else if (to.name === 'Login' && isAuthenticated) {
        console.log('已登录用户访问登录页，重定向到上传页');
        next('/upload');
    } else {
        console.log('允许访问当前路由');
        next();
    }
});

=======
})
>>>>>>> f425cfb0320ced29f9e28f379fa4c77eebf50d68
export default router